<?php
namespace app\admin\controller;

use app\admin\model\Member;
use app\first\model\Article;

class Dashboard extends Base{
    /**
     * @return \think\Response
     * @route('admin/dashboard/init','get')
     */
    public function init(){
        $user = (new Member())
            ->whereTime('create_time', 'week')
            ->where('is_auth','eq', 0)
            ->count('*');
        $resource = (new Article())
            ->whereTime('create_time', 'week')
            ->where('status','gt', -1)
            ->count('*');
        $shenhe = (new Article())
            ->whereTime('create_time', 'week')
            ->where('status','gt', 0)
            ->count('*');
        $total = [
            'user'=>$user,
            'resource'=>$resource,
            'recheck'=>$shenhe
        ];
        return $this->__s('',$total);
    }

    /**
     * @route('admin/dashboard/user','get')
     * @return \think\Response
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function userCount(){
        $user = new Member();
        $list = $user->getWeekData([]);
        return $this->__s('',$list);
    }
    /**
     * @route('admin/dashboard/resource','get')
     */
    public function resource(){
        $res = new Article();
        $list = $res->getWeekData();
        return $this->__s('',$list);
    }

    /**
     * @route('admin/dashboard/recheck','get')
     * @return \think\Response
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function recheck(){
        $res = new Article();
        $list = $res->getWeekData();
        return $this->__s('',$list);
    }
}